{{- define "simple_bridge_resources" }}
cpu: 25m
memory: 50Mi
{{- end }}

{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: simple-bridge
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "simple-bridge" "workload-resource-policy.deckhouse.io" "every-node")) | nindent 2 }}
spec:
  targetRef:
    apiVersion: "apps/v1"
    kind: DaemonSet
    name: simple-bridge
  updatePolicy:
    updateMode: "Auto"
  resourcePolicy:
    containerPolicies:
    - containerName: "simple-bridge"
      minAllowed:
        {{- include "simple_bridge_resources" . | nindent 8 }}
      maxAllowed:
        cpu: 50m
        memory: 50Mi
{{- end }}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: simple-bridge
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list $ (dict "app" "simple-bridge")) | nindent 2 }}
spec:
  updateStrategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app: simple-bridge
  template:
    metadata:
      labels:
        app: simple-bridge
    spec:
      imagePullSecrets:
      - name: deckhouse-registry
      {{- include "helm_lib_priority_class" (tuple . "system-node-critical") | nindent 6 }}
      {{- include "helm_lib_tolerations" (tuple . "any-node" "with-uninitialized") | nindent 6 }}
      {{- include "helm_lib_module_pod_security_context_run_as_user_deckhouse" . | nindent 6 }}
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      serviceAccountName: {{ .Chart.Name }}
      containers:
      - name: simple-bridge
        image: {{ include "helm_lib_module_image" (list . "simpleBridge") }}
        {{- /*
          UID: 0 GID:0 using for privilege access for iptables because using hostNetwork
        */}}
        securityContext:
          allowPrivilegeEscalation: true
          capabilities:
            add:
            - NET_RAW
            - NET_ADMIN
            drop:
            - ALL
          runAsGroup: 0
          runAsNonRoot: false
          runAsUser: 0
        command:
        - /bin/simple-bridge
        env:
        {{- if hasKey .Values.global "clusterConfiguration" }}
          {{- if .Values.global.clusterConfiguration.cloud }}
        - name: ROUTE_POD_NETWORK_TO_GW
          value: "{{ if eq .Values.global.clusterConfiguration.cloud.provider "Yandex" }}true{{ else }}false{{ end }}"
          {{- end }}
        {{- end }}
        - name: POD_SUBNET
          value: {{ .Values.global.discovery.podSubnet | quote }}
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        volumeMounts:
        - name: run
          mountPath: /run
        - name: cni
          mountPath: /etc/cni/net.d
        - name: tmp
          mountPath: /tmp
        resources:
          requests:
            {{- include "helm_lib_module_ephemeral_storage_logs_with_extra" 10 | nindent 12 }}
{{- if not (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
            {{- include "simple_bridge_resources" . | nindent 12 }}
{{- end }}
      volumes:
      - name: run
        hostPath:
          path: /run
      - name: cni
        hostPath:
          path: /etc/cni/net.d
      - name: tmp
        emptyDir: {}
